package com.bugreport.configuration;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.bugreport.test.utils.BugTrackerTestConfiguration1;

public class BTCUrlMatchingTestCase {

	@Test
	public void verifyExactUrl() {
		BugTrackerTestConfiguration1 config = new BugTrackerTestConfiguration1(1, "1", "^www.foo.bar$");
		assertTrue(config.isUrlMatching("www.foo.bar"));
		assertFalse(config.isUrlMatching("www.foo.bar/index.html"));
	}

	@Test
	public void verifyWithOrWithoutProtocol() {
		BugTrackerTestConfiguration1 config = new BugTrackerTestConfiguration1(1, "1", "^(http://)?www.foo.bar$");
		assertTrue(config.isUrlMatching("www.foo.bar"));
		assertTrue(config.isUrlMatching("http://www.foo.bar"));
	}

	@Test
	public void verifyDifferentProtocol() {
		BugTrackerTestConfiguration1 config = new BugTrackerTestConfiguration1(1, "1",
				"^((http://)|(https://))?www.foo.bar$");
		assertTrue(config.isUrlMatching("www.foo.bar"));
		assertTrue(config.isUrlMatching("http://www.foo.bar"));
		assertTrue(config.isUrlMatching("https://www.foo.bar"));
		assertFalse(config.isUrlMatching("ftp://www.foo.bar"));
	}

	@Test
	public void verifyWhateverUrlAfterDomainName() {
		BugTrackerTestConfiguration1 config = new BugTrackerTestConfiguration1(1, "1", "^www.foo.bar(/.*)?$");
		assertTrue(config.isUrlMatching("www.foo.bar"));
		assertTrue(config.isUrlMatching("www.foo.bar/foo.html"));
		assertTrue(config.isUrlMatching("www.foo.bar/bar/foo.html"));
	}

	@Test
	public void verifyOnlyHtmlPages() {
		BugTrackerTestConfiguration1 config = new BugTrackerTestConfiguration1(1, "1", "^www.foo.bar/(.+)\\.html$");
		assertFalse(config.isUrlMatching("www.foo.bar"));
		assertTrue(config.isUrlMatching("www.foo.bar/foo.html"));
		assertTrue(config.isUrlMatching("www.foo.bar/bar/foo.html"));
		assertFalse(config.isUrlMatching("www.foo.bar/bar/foo.do"));
	}
}
